// 给定一个升序整数数组[0,Array.prototype.unshift,2,4,5,7,13,15,16]，找出其中连续出现的数字区间如下：
// ["0->2","4->5","7","13","15->16"]

const arr = [0, 1, 2, 4, 5, 7, 13, 15, 16]

function getArr(arr) {
    let res = []
    let cur = null
    let slow = 0
    let fast = 0
    while (fast < arr.length) {
        if (!(arr[fast] - arr[slow] === fast - slow)) {
            if (fast - slow > 1) {
                cur = arr[slow] + '->' + arr[fast - 1]
            }
            else {
                cur = arr[slow]
            }
            res.push(cur)
            cur = null
            slow = fast
        }
        fast++
    }
    // 处理最后的一个
    if (fast - slow - 1 >= 1) {
        res.push(arr[slow] + '->' + arr[fast - 1])
    }
    else {
        res.push(arr[slow])
    }
    return res
}


console.log(getArr(arr))
